

#定义一个家类
class Home:
    def __init__(self,area):
        self.area = area #房间剩余面积
        self.light = "on" #灯默认亮的
        self.containsItem = [] #家里的东西

    def __str__(self):
        msg = "家当前可用面积："+str(self.area)
        msg += "\t"
        if len(self.containsItem) > 0:
            msg += "当前家里的物品有："
            for temp in self.containsItem:
                msg += temp.getName()+","
            msg = msg[:-1]
        else:
            msg += "当前家里没有任何东西"      
        if self.light == "on":
            msg += "\t" + "当前灯是开着的，所有物品都是可见的。"
        else:
            msg += "\t" + "当前灯是关着的，所有物品都是不可见的。"
        return msg

    #添加新物品到家里
    def addItem(self,item):
        needArea = item.getArea()
        if self.area > needArea:
            self.containsItem.append(item)
            self.area -= needArea
    def turnoff(self):
        self.light = "off"
        #修改所有物品的可见度
        for temp in self.containsItem:
            temp.turnoff()


    
#定义家具类
class Bed:
    def __init__(self,name,area):
        self.name = name
        self.area = area
        self.light = "on"
    def __str__(self):
        msg = "这是："
        msg += self.name + " 面积为：" + str(self.area) + " 当前的可见度为：" + self.light
        return msg
    def getName(self):
        return self.name
    def getArea(self):
        return self.area
    def turnoff(self):
        self.light = "off"
myHome = Home(100)
print(myHome)

bed = Bed("席梦思",4)
print(bed)
myHome.addItem(bed)
print(myHome)
bed2 = Bed("木板床",2)
print(bed2)
myHome.addItem(bed2)
print(myHome)

print("="*30)

myHome.turnoff()
print(bed)
print(bed2)